import dayjs from "dayjs";

/** 格式化提交数据, 只保留初始化数据中的字段 */
export function onlySubmitData<T extends Record<keyof any, any>>(initData: T, formData: Partial<T>): T {
    Object.keys(initData).forEach((key) => {
        // @ts-ignore
        initData[key] = formData[key];
    });
    return initData;
}

/** 格式化表格数据 */
export function fmtTableData(): {
    text: (val: string) => string;
    date: (val: string) => string;
} {
    return {
        text: (val: string) => val || "/",
        date: (val: string) => dayjs(val).format("YYYY-MM-DD HH:mm:ss"),
    };
}
